package com.firefly.admin.system.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.firefly.admin.common.annotations.annotation.OperationLog;
import com.firefly.admin.common.enums.OperationModuleEnum;
import com.firefly.admin.common.enums.OperationTypeEnum;
import com.firefly.admin.common.vo.Result;
import com.firefly.admin.monitor.vo.SelectResult;
import com.firefly.admin.system.entity.FySystemWhiteList;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import com.firefly.admin.system.service.FySystemWhiteListService;
import com.firefly.admin.system.vo.SystemWhiteListQueryVo;
import com.firefly.admin.system.vo.SystemWhiteListStatusUpdateVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Api(tags = "系统白名单接口API")
@RestController
@RequestMapping("/system/white/list")
public class FySystemWhiteListController {

    @Autowired
    private FySystemWhiteListService fySystemWhiteListService;

    /**
     * 分页查询系统白名单接口
     *
     * @param systemWhiteListQueryVo 分页查询参数
     * @return 分页列表
     */
    @ApiOperation(value = "分页查询系统白名单接口", notes = "分页查询系统白名单接口", httpMethod = "GET")
    @PreAuthorize(value = "hasAuthority('system:white:list')")
    @GetMapping("/page")
    public Result<Page<FySystemWhiteList>> getSystemWhiteListPage(SystemWhiteListQueryVo systemWhiteListQueryVo) {
        return fySystemWhiteListService.getSystemWhiteListPage(systemWhiteListQueryVo);
    }

    /**
     * 系统白名单信息新增接口
     *
     * @param fySystemWhiteList 系统白名单信息
     * @return 新增结果
     */
    @ApiOperation(value = "系统白名单信息新增接口", notes = "系统白名单信息新增接口", httpMethod = "POST")
    @OperationLog(module = OperationModuleEnum.SYSTEM_MANAGE, operateType = OperationTypeEnum.SYSTEM_WHITE_LIST, operateDesc = "白名单新增")
    @PreAuthorize(value = "hasAuthority('system:white:list:add')")
    @PostMapping("/add")
    public Result<FySystemWhiteList> add(@RequestBody FySystemWhiteList fySystemWhiteList) {
        return fySystemWhiteListService.add(fySystemWhiteList);
    }

    /**
     * 系统白名单信息编辑接口
     *
     * @param fySystemWhiteList 系统白名单信息
     * @return 编辑结果
     */
    @ApiOperation(value = "系统白名单信息编辑接口", notes = "系统白名单信息编辑接口", httpMethod = "POST")
    @OperationLog(module = OperationModuleEnum.SYSTEM_MANAGE, operateType = OperationTypeEnum.SYSTEM_WHITE_LIST, operateDesc = "白名单编辑")
    @PreAuthorize(value = "hasAuthority('system:white:list:update')")
    @PostMapping("/update")
    public Result<FySystemWhiteList> update(@RequestBody FySystemWhiteList fySystemWhiteList) {
        return fySystemWhiteListService.update(fySystemWhiteList);
    }

    /**
     * 系统白名单状态修改接口
     *
     * @param systemWhiteListStatusUpdateVo 系统白名单状态编辑参数
     * @return 操作结果
     */
    @ApiOperation(value = "系统白名单状态修改接口", notes = "系统白名单状态修改接口", httpMethod = "POST")
    @OperationLog(module = OperationModuleEnum.SYSTEM_MANAGE, operateType = OperationTypeEnum.SYSTEM_WHITE_LIST, operateDesc = "白名单修改状态")
    @PreAuthorize(value = "hasAuthority('system:white:list:update:status')")
    @PostMapping("/update/status")
    public Result<String> updateStatus(@RequestBody SystemWhiteListStatusUpdateVo systemWhiteListStatusUpdateVo) {
        return fySystemWhiteListService.updateStatus(systemWhiteListStatusUpdateVo);
    }

    /**
     * 系统白名单信息删除接口
     *
     * @param whiteListId 白名单ID
     * @return 删除结果
     */
    @ApiOperation(value = "系统白名单信息删除接口", notes = "系统白名单信息删除接口", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "whiteListId", required = true, value = "白名单ID", paramType = "query", dataType = "Long")
    })
    @OperationLog(module = OperationModuleEnum.SYSTEM_MANAGE, operateType = OperationTypeEnum.SYSTEM_WHITE_LIST, operateDesc = "白名单删除")
    @PreAuthorize(value = "hasAuthority('system:white:list:delete')")
    @PostMapping("/delete")
    public Result<String> delete(Long whiteListId) {
        return fySystemWhiteListService.delete(whiteListId);
    }

    /**
     * 白名单类型枚举列表查询接口
     *
     * @return 白名单类型列表
     */
    @ApiOperation(value = "白名单类型枚举列表查询接口", notes = "白名单类型枚举列表查询接口", httpMethod = "GET")
    @GetMapping("/select/enum/list")
    public Result<List<SelectResult>> getWhiteListTypeEnumList() {
        return fySystemWhiteListService.getWhiteListTypeEnumList();
    }

    /**
     * 获取敏感数据白名单可选用户和角色接口
     *
     * @return 可选用户和角色
     */
    @ApiOperation(value = "获取敏感数据白名单可选用户和角色接口", notes = "获取敏感数据白名单可选用户和角色接口", httpMethod = "GET")
    @GetMapping("/sensitive/data")
    public Result<Map<String, List<SelectResult>>> getSensitiveDataList() {
        return fySystemWhiteListService.getSensitiveDataList();
    }
}
